# ally_soldier_fervor.gd
extends TechnologyResource
class_name AllySoldierFervor

var hp_threshold = 0.5
var attack_speed_increase = 0.3

func _init() -> void:
	display_name = "Soldier Fervor"
	description = "当友方士兵生命值低于50%时，攻击速度提升30%"
	tech_id = "ally_soldier_fervor"
	super()

# 激活科技（连接信号）
func activate():
	GlobalSignal.gs_ally_hp_changed.connect(_on_ally_hp_changed)

# 停用科技（断开信号）
func deactivate():
	GlobalSignal.gs_on_ally_hp_changed.disconnect(_on_ally_hp_changed)

func _on_ally_hp_changed(ally: AllyBaseUnit, hp: int, max_hp: int) -> void:
	if ally is AllySoldier: # 确保类型正确
		for skill in ally.all_skill_instances:
			if skill.skill_type == GameConstant.SKILL_TYPE.ATTACK:
				var should_boost = (hp <= max_hp * hp_threshold)
				skill.cooldown = skill.base_cooldown / (1 + attack_speed_increase) if should_boost else skill.base_cooldown
